
import {
  _form
} from './index.js'
import {
  _grid
} from './grid.js'
import {
  _list
} from './list.js'
import {
  _svg
} from '../svg/index.js'
import {
  _canvas
} from '../canvas/index.js'
import { _btn } from './btn.js'
import { _type } from '../utils/index.js'
import { _webgl } from '../webgl/index.js'
import {
  updateRoute
} from './route.js'
export const renderContent = (t) => {
  let { name, content, contentType, render } = t

  // 更新路由
  updateRoute(t)

  let contentConfig = _type(content) === 'function' ? content() : content

  contentConfig.name = name

  let isHtml
  let str = ""
  switch (contentType.toLowerCase()) {
    case 'form':
      str = _form(contentConfig)
      break
    case 'grid':
      str = _grid(contentConfig, contentConfig.data)
      break
    case 'list':
      str = _list(contentConfig, render)
      break
    case 'html':
      str = contentConfig
      isHtml = true
      break
    case 'svg':
      str = _svg(contentConfig)
      break;
    case 'canvas':
      str = _canvas(contentConfig)
      break;
    case 'btns':
      str = contentConfig.map(t => _btn(t))
      break
    case 'webgl':
      str = _webgl(contentConfig)
      break;
    default:
      str = contentConfig
    // if (_type(contentConfig) === 'function') {
    //   content = contentConfig()
    // } else {
    //   content = contentConfig
    // }

  }

  return {
    content: str,
    isHtml
  }

}